package pbl;

import java.net.*;

/**
 * 
 * @author @author AMPM
 *
 */

public class UdpSender {
	public static void main(String args[ ]) throws Exception{ 
		// an object representing this computers IP address
		InetAddress receiversAddress = InetAddress.getByName("localhost");
		
		int receiversPort = 6789;		                                                 
		DatagramSocket datagramSocket = new DatagramSocket();
		
		// the string we want to send
		String messageAsString = "Hello";
		
		// data for sending is flattened and wrapped in a DatagramPacket object
		byte [ ] message = messageAsString.getBytes();
		int messageLength = messageAsString.length();
		DatagramPacket datagramPacket = new DatagramPacket(message, messageLength, receiversAddress, receiversPort);
		
		// the datagram packet is sent
		datagramSocket.send( datagramPacket );
  }
}